﻿@model IEnumerable<Navigation>
@{
    ApplicationBase application = ViewData.Get<ApplicationBase>("application", null);
    IEnumerable<ApplicationManagementOperation> managementOperations = ViewData.Get<IEnumerable<ApplicationManagementOperation>>("ManagementOperations", new List<ApplicationManagementOperation>());
    managementOperations = managementOperations.Where(n => n.ApplicationId == application.ApplicationId);

    User currentUser = (User)UserContext.CurrentUser;

    int currentNavigationId = 0;
    if (Html.ViewContext.RouteData.Values.ContainsKey("CurrentNavigationId"))
    {
        currentNavigationId = Html.ViewContext.RouteData.Values.Get<int>("CurrentNavigationId", 0);
    }
}
<div class="tn-section tn-helper-clearfix">
    @if (application != null)
    {
        <h2 class="tn-pagename">
            <span class="tn-icon-special tn-special-icon-@application.ApplicationKey.ToLower()"></span>@Tunynet.Globalization.ResourceAccessor.GetString("ApplicationName_" + application.ApplicationKey, application.ApplicationId)</h2>
    }

    @if (managementOperations != null && managementOperations.Count() > 0)
    {            
        <div class="tn-shortcut">
            @foreach (var managementOperation in managementOperations)
            {
                if (!managementOperation.IsVisible(UserContext.CurrentUser))
                {
                    continue;
                }
                IconTypes? iconType = null;
                if (!string.IsNullOrEmpty(managementOperation.IconName))
                {
                    iconType = (IconTypes)Enum.Parse(typeof(IconTypes), managementOperation.IconName, false);
                }
                string managementOperationUrl = managementOperation.GetUrl(Html.ViewContext.RouteData.Values);
                if (currentUser == null)
                {
                    managementOperationUrl = SiteUrls.Instance().Login(returnUrl: managementOperationUrl);
                }
                @Html.LinkButton(managementOperation.OperationText, managementOperationUrl, HighlightStyles.Primary, ButtonSizes.Large, iconType: iconType, htmlAttributes: new { target = managementOperation.NavigationTarget })                
            }
        </div>
    }
</div>
<div class="tn-submenu-area">
    <div class="tn-submenu-inner">
        <ul id="tn-submenu" class="tn-submenu tn-drop-menu tn-helper-clearfix">
            @{ 
                int i = 0;
                string url = string.Empty;                
                
            }
            @foreach (Navigation navigation in Model)
            {

                if (!navigation.IsVisible(UserContext.CurrentUser))
                {
                    continue;
                }

                url = navigation.GetUrl(Html.ViewContext.RouteData.Values);
                url = string.IsNullOrEmpty(url) ? SiteUrls.Instance().Login(true) : url;
                <li class="tn-submenu-item @if (navigation.IsCurrent(currentNavigationId))
                                           {  @("tn-selected") }"><a class="tn-submenu-link" href="@url" target="@navigation.NavigationTarget">
                                               @navigation.Text</a></li>
                                           i++;
                                           if (i >= 7)
                                           {
                                               break;
                                           }
            }
            @if (Model.Count() > 7)
            {
                <li class="tn-submenu-item"><a class="tn-submenu-link" data_menu_clicktrigger="true"
                    href="javascript:;">更多</a>
                    <ul class="tn-widget-content tn-border-gray" style="display: none">
                        @foreach (var navigation in Model.Skip(7))
                        {
                            if (!navigation.IsVisible(UserContext.CurrentUser))
                            {
                                continue;
                            }
                            url = navigation.GetUrl(Html.ViewContext.RouteData.Values);
                            url = string.IsNullOrEmpty(url) ? SiteUrls.Instance().Login(true) : url;
                            <li class="tn-submenu-item @if (navigation.IsCurrent(currentNavigationId))
                                                       {  @("tn-selected") }"><a href="@url" target="@navigation.NavigationTarget">
                                                           @navigation.Text</a></li>
                        }
                    </ul>
                </li>
            }
        </ul>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function ($) {
        $('#tn-submenu').dcMegaMenu({
            rowItems: '1',
            speed: 'fast',
            effect: 'fade'
        });
        $("#tn-submenu li.tn-submenu-item").hover(
		function () {
		    $(this).addClass("tn-bg-gray");
		},
		function () {
		    $(this).removeClass("tn-bg-gray");
		}
	);
    });
</script>
